﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyUrnaVirtual.Models;
using MyUrnaVirtual.DataRepository;

namespace MyUrnaVirtual.Controllers
{
    public class AdminPersonasController : Controller
    {
        //
        // GET: /AdminPersonas/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Crear()
        {
            AdminPersonasViewModel model = new AdminPersonasViewModel();

            return View(model);
        }

        [HttpPost]//postback del formulario Crear . 
        public ActionResult Crear(AdminPersonasViewModel model)
        {
            AdminPersonasRepository.Guardar(model);

            return View("Index");
        }

        public ActionResult Editar(int dni)
        {
            AdminPersonasViewModel model = new AdminPersonasViewModel();
            Personas pers = AdminPersonasRepository.Get(dni);

            model.Dni = pers.dni;
            model.Nombre = pers.nombre;
            model.Apellido = pers.apellido;

            return View(model);
        }

        [HttpPost]//postback del formulario editar. 
        public ActionResult Editar(AdminPersonasViewModel model)
        {
            AdminPersonasRepository.Editar(model);

            return View("Index");
        }

        public ActionResult Eliminar(int dni)
        {
            AdminPersonasRepository.Eliminar(dni);
            return View("Index");
        }

    }
}

